package com.example.learndemo;

public class TestCommon {
	public static void print(int[] data) {
		System.out.print("[");
		for (int i = 0; i < data.length; i++) {
			if (i == data.length - 1) {
				System.out.print(data[i] + "]");
			} else {
				System.out.print(data[i] + ",");
			}
		}
		System.out.println();
	}

	public static void equals(int[]data1, int[]data2) throws Exception {
		if(data1.length!=data2.length){
			throw new Exception("长度不一");
		}
		for (int i = 0; i < data1.length; i++) {
			if(data1[i]!=data2[i]){
				throw new Exception("index="+i+"的元素不同");
			}
		}
	}

	public static int[] creatArr(int length) {
		int[] arr = new int[length];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = (int) (Math.random() * length * 10);
		}
		System.out.print("创建数组==》");
		// print(arr);
		return arr;
	}

	public static int[] copyArr(int[] data) {
		int[] copyArr = new int[data.length];
		System.arraycopy(data, 0, copyArr, 0, data.length);
		return copyArr;
	}
}
